<template>
	<view>
		<kzPageMyColor :userInfo1="user1" @login="login" @goTo="goTo"
			@clearStorage="clearStorage"/>
		<login ref="login" @succ="loginSucc"></login>
		<tabbar></tabbar>
	</view>
</template>

<script>
	import kzPageMyColor from '@/components/kz-page-my-color-1/kz-page-my-color-1.vue';
	export default {
	  name: "mine",
	  data() {
	    return {
	     user1: {}, //用户信息
		 isLogin:false
	    };
	  },
	  components: { kzPageMyColor },
	  onShow() {
		this.user1 = uni.getStorageSync('user')
	  	if (uni.getStorageSync('token')) {
	  		this.isLogin = true
	  	} else {
	  
	  		this.$nextTick(() => {
	  			this.$refs.login.modal = true;
	  		})
	  	}
	  },
	  methods: {
		  //登录成功回调
			loginSucc(data){
			  this.user1 = data.user
			},
			login() {
				if (!uni.getStorageSync('token')) {
					this.$refs.login.modal = true;
					return;
				} else {
					uni.navigateTo({
						url: '/pages/mine/set'
					});
				}
			},
			goTo(page) {
				if (!uni.getStorageSync('token')) {
					this.$refs.login.modal = true;
					return;
				} else {
					console.log(page);
					// this.utils.goto(page)
					uni.navigateTo({
						url: page
					});
				}
			},
			clearStorage() {
				let that = this
				uni.showModal({
					title: '提醒',
					content: '确认要退出登录吗？（将清理用户信息等数据）',
					confirmColor: '#4A90E2',
					success: (t) => {
						t.confirm ?
							(uni.showLoading({
									title: '正在退出...',
									mask: !0
								}),
								uni.clearStorage({
									success: () => {
										that.user1 = {}
										// uni.setStorageSync('user', '');
										// uni.setStorageSync('token', '');
										// uni.setStorageSync('openid', '');
										uni.clearStorage();
									},
									fail: (t) => {
										console.log('fail');
									},
									complete: function(t) {
										setTimeout(function() {
											uni.hideLoading();
										}, 1000);
									}
								})
								// ,
								// this.getSetting()
							) :
							t.cancel && console.log('取消');
					}
				});
			},
	  }
	};
</script>

<style lang="scss" scoped>
	
</style>